package com.zprmb.udzt.zhitoudialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.TextView;

import com.zprmb.udzt.R;

public class ZhiTouAlertDialog extends Dialog {
    private OnSureClickListener mListener;
    private Button button_sure;
    private Button button_cancel;
    private TextView title;
    private TextView content;
    private ZhiTouAlertDialog dialog;
    private String type = "";
    private Context context; // 上下文对象

    public ZhiTouAlertDialog(Context context) {
        super(context);
        // TODO Auto-generated constructor stub
    }

    public ZhiTouAlertDialog(Context context, OnSureClickListener Listener) {
        super(context);
        mListener = Listener;
        // TODO Auto-generated constructor stub
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);


        // No Titlebar
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.v6_guide_alert_dialog);

        setView();
    }

    public void setText(String text) {
        content.setText(text);
    }

    public void setTitle(String title) {
        this.title.setText(title);
    }

    public void setButtonCancel(String text) {
        button_cancel.setText(text);
    }

    public void setButtonsure(String text) {
        button_sure.setText(text);
    }

    public void setType(String text) {
        type = text;
    }

    public String getType() {
        return type;
    }

    private void setView() {
        button_sure = (Button) findViewById(R.id.button_sure);
        button_cancel = (Button) findViewById(R.id.button_cancel);
        title = (TextView) findViewById(R.id.alert_title);
        content = (TextView) findViewById(R.id.alert_text);

        //这里的监听事件，因为该类继承lDialog类的DialogInterface,而DialogInterface中也有OnClickListener，因此需要用到全名View.OnClickListener
        button_sure.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                mListener.onConfirm();
                dismiss();
            }
        });
        button_cancel.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                mListener.onCancle();
                dismiss();
            }
        });
    }

    public interface OnSureClickListener {
        void onConfirm();

        void onCancle();
    }

}
